﻿@model GPS.ENTITYS.ViewModelDDTTN_KQTN
@using PagedList.Mvc;
@using GPS.Helpers;
@{
    ViewBag.Title = "Điểm học viên tốt nghiệp";
}

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.maskedinput.js"></script>
<script src="~/Scripts/datepicker.js"></script>

<link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="~/Scripts/locales/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>


<script src="~/Scripts/datepicker.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
<script src="~/Scripts/jquery.maskMoney.js"></script>
<script src="~/Scripts/jquery.number.js"></script>
<script src="~/Scripts/jquery.masknumber.js"></script>
<script src="~/Scripts/moment.js"></script>

<link href="~/dist/css/bootstrap-select.css" rel="stylesheet" />
<script src="~/dist/js/bootstrap-select.js"></script>


<div class="container fdb-div-content fdb-div-corner-all">
    <h3 class="text-center fdb-title-search-form">Thông tin Điểm tốt nghiệp học viên</h3>
    <div class="row">
        @using (Html.BeginForm("Index", "GPS_DiemTotNghiep", FormMethod.Get))
        {

            <div class="list-group">
                <fieldset class="fs_body">
                    <legend class="head_title">Điều Kiện Tìm Kiếm</legend>

                    <div class="row criteria_search">
                        <div class="row margin-top-05">
                            <div class="col-md-2 control-label">
                                Đơn vị đào tạo
                            </div>
                            <div class="col-md-4">
                                @Html.DropDownListFor(model => model.pDVGTVT_MA, (SelectList)ViewBag.DVGTVT_MAs, string.Empty, new { @class = "form-control", @id = "DVGTVT_MA_dll" })
                            </div>
                            <div class="col-md-2 control-label">
                                Khóa đào tạo
                            </div>
                            <div class="col-md-4">
                                @Html.DropDownListFor(model => model.pKH_MA, (SelectList)ViewBag.KH_MAs, string.Empty, new { @title = "Vui lòng chọn khóa học...", @id = "KH_MA_ddl", @style = "font-weight:bold;width:300px" })
                            </div>
                        </div>
                        <div class="row margin-top-05">

                            <div class="col-md-2 control-label">
                                Mã học viên
                            </div>
                            <div class="col-md-4">
                                @Html.TextBoxFor(model => model.pHV_MA, new { @class = "form-control" })
                            </div>
                            <div class="col-md-2 control-label">
                                Họ tên
                            </div>
                            <div class="col-md-4">
                                @Html.TextBoxFor(model => model.pHV_HOTEN, new { @class = "form-control" })
                            </div>
                        </div>

                        <div class="row margin-top-05">
                            <div class="col-md-2 control-label">
                                Số CMND
                            </div>
                            <div class="col-md-4">
                                @Html.TextBoxFor(model => model.pHV_CMND, new { @class = "form-control" })
                            </div>

                            <div class="col-md-2 control-label">
                                Hạng đào tạo
                            </div>
                            <div class="col-md-4">
                                @Html.DropDownListFor(model => model.pHANG_DT, (SelectList)ViewBag.HANGDT_MAs, string.Empty, new { @class = "form-control", @id = "HANGDT_MA_dll" })
                            </div>
                        </div>

                        <div class="row margin-top-05">
                            <div class="col-md-2 control-label">
                                Tên khóa Tốt nghiệp
                            </div>
                            <div class="col-md-4">
                                @Html.DropDownListFor(model => model.pSO_QD_TN, (SelectList)ViewBag.DTTN_QDs, string.Empty, new { @class = "form-control", @id = "SO_QD_TN_dll" })
                            </div>


                        </div>

                    </div>

                    <div class="row margin-top-05 btn_search">
                        <button type="submit" class="btn btn-warning btn-sm">
                            <span class="glyphicon glyphicon-search"></span> Tìm kiếm
                        </button>
                    </div>
                </fieldset>
            </div>
        }
        <br />
        <div id="dialog"></div>
        <div class="row">
            <fieldset class="fs_body">
                <legend class="head_title">Kết quả tìm kiếm</legend>

                <div class="row divbtnFielset">
                    <div style="float: left;">
                        @*@Html.NoEncodeActionLink("<span class='glyphicon glyphicon-plus'></span> Thêm mới", "Thêm mới", "Create", "GPS_DiemTotNghiep", null, htmlAttributes: new { @class = "btn btn-warning btn-sm" })*@

                        @*<button type="submit" class="btn btn-primary btn-sm" name="SearchButton" value="Xuất Excel">
                                <i class='fa fa-file-excel-o'></i> Xuất Excel
                            </button>
                            @Html.NoEncodeActionLink("<i class='fa fa-file-excel-o'></i> Import Excel", "Import Excel", "ImportExcel", "GPS_MonHoc", null, htmlAttributes: new { @class = "btn btn-primary btn-sm" })*@
                    </div>
                    <div style="float: right;">
                        <label id="lblMessageTotal" style="color:blue; font-weight:bold">Tổng số bản ghi: @ViewBag.TotalRow</label>
                    </div>
                </div>

                <div class="row" style="clear:both; padding: 5px 0;">
                    <table class="table table-hover table-bordered table-condensed" id="tabledata">
                        <tr>
                            <th>
                                STT
                            </th>
                            <th>
                                Tên học viên
                            </th>

                            <th style="width:200px">
                                Đơn vị GTVT
                            </th>
                            <th>
                                Giới tính
                            </th>
                            <th>
                                Ngày sinh
                            </th>
                            <th>
                                Ngày KQTN
                            </th>
                            <th>
                                Điểm TNLT
                            </th>
                            <th>
                                Điểm TNTH
                            </th>
                            <th>
                                Điểm TNTD
                            </th>
                            <th>
                                Điểm TNCC
                            </th>
                            <th>
                                Điểm TBC
                            </th>
                            <th>
                                Điểm TNTB
                            </th>
                            <th>
                                Điểm TKKH
                            </th>
                            @*<th>
                                    Người nhập
                                </th>*@
                            <th></th>
                        </tr>
                        @{
                            if (Model.SearchResults != null)
                            {
                                var i = 0;
                                var _display = "block";
                                foreach (var item in Model.SearchResults)
                                {

                                    if (item.ID != null)
                                    {

                                        _display = "block";
                                    }
                                    else
                                    {

                                        _display = "none";
                                    }

                                    <tr>
                                        <td>
                                            @(i + 1)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.HV_HO_TEN)
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => item.HV_DVGTVT_TEN)
                                        </td>
                                        @*<td>
                                                @Html.DisplayFor(modelItem => (item.DTTN_KQTN_HV_GIOITINH))
                                            </td>*@
                                        <td>
                                            @{
                                    if (item.HV_GIOITINH == "F")
                                    {
                                        @Html.Raw("Nữ")
                                    }
                                    else
                                    {
                                        @Html.Raw("Nam")
                                    }
                                            }
                                        </td>
                                        <td>
                                            @Html.DisplayFor(modelItem => (item.HV_NGAYSINH))

                                            @Html.HiddenFor(modelItem => item.ID, new { @id = "ID_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.HV_DVGTVT_MA, new { @id = "HV_DVGTVT_MA_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.HV_KH_MA, new { @id = "HV_KH_MA_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.DTTN_ID, new { @id = "DTTN_ID_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.HV_MA, new { @id = "HV_MA_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.DTTN_QD_ID, new { @id = "DTTN_QD_ID_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.DTTN_HGPLX_MA, new { @id = "DTTN_HGPLX_MA_" + i.ToString() })
                                            @Html.HiddenFor(modelItem => item.DTTN_KQTN_TONG, new { @id = "DTTN_KQTN_TONG_" + i.ToString() })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_NGAYTN))*@
                                            @Html.TextBoxFor(modelItem => item.DTTN_KQTN_NGAYTN, "{0:dd/MM/yyyy}", new { @class = "form-control", @id = "DTTN_KQTN_NGAYTN_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_LT))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_LT), new { @class = "form-control txtnumber", @id = "DTTN_KQTN_LT_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TH))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_TH), new { @class = "form-control txtnumber", @id = "DTTN_KQTN_TH_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TD))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_TD), new { @class = "form-control txtnumber", @id = "DTTN_KQTN_TD_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TD))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_CC), new { @class = "form-control txtnumber", @id = "DTTN_KQTN_CC_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TBC))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_TBC), new { @class = "form-control txtnumber", @id = "DTTN_KQTN_TBC_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TB))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_TB), new { @class = "form-control txtnumber", @readonly = "readonly", @id = "DTTN_KQTN_TB_" + i.ToString(), @type = "text" })
                                        </td>
                                        <td>
                                            @*@Html.DisplayFor(modelItem => (item.DTTN_KQTN_TKKH))*@
                                            @Html.TextBoxFor(modelItem => (item.DTTN_KQTN_TKKH), new { @class = "form-control txtnumber", @readonly = "readonly", @id = "DTTN_KQTN_TKKH_" + i.ToString(), @type = "text" })
                                        </td>

                                        <td align="left">
                                            <div>
                                                @*<a href="@Url.Action("Detail", "GPS_DiemTotNghiep", new { id1 = item.DTTN_KQTN_DVGTVT_MA, id2 = item.DTTN_KQTN_KH_MA, id3 = item.DTTN_KQTN_KH_LOP_MA, id4 = item.DTTN_KQTN_HV_MA })" data-modal="">
                                                        <img src="@Url.Content("~/fonts/grid-view-icon.png")" title="Xem chi tiết" />
                                                    </a>*@
                                                <a href="javascript:void()" class="savediemhocvien" id="save_@(i.ToString())">

                                                    <img src="@Url.Content("~/fonts/save24.png")" title="lưu điểm tn học viên" />
                                                </a>
                                                <a href="@Url.Action("Create", "GPS_DiemTotNghiep", new { id1 = item.HV_DVGTVT_MA, id2 = item.HV_KH_MA, id3 = item.DTTN_ID, id4 = item.HV_MA, id5 = item.DTTN_QD_ID, id6 = item.DTTN_HGPLX_MA })" id="add_@(i.ToString())"
                                                   style="display:@(_display=="block"?"none":"block")">
                                                    <img src="@Url.Content("~/fonts/grid-add-icon.png")" title="Nhập điểm TN học viên" />
                                                </a>
                                                <a href="@Url.Action("Edit", "GPS_DiemTotNghiep", new { id = item.ID, id6 = item.DTTN_HGPLX_MA })" id="edit_@(i.ToString())"
                                                   style="display:@(_display == "block"?"block":"none")">
                                                    <img src="@Url.Content("~/fonts/grid-edit-icon.png")" title="Sửa điểm TN học viên" />
                                                </a>
                                                @*@if (_display == "block")
                                                    {*@
                                                <a href="@Url.Action("Delete", "GPS_DiemTotNghiep", new { id = item.ID })" onclick="return confirm('Bạn Thật Sự Muốn Xóa điểm TN của học viên Này!!!')"
                                                   id="delete_@(i.ToString())" style="display:@(_display == "block"?"block":"none")">
                                                    <img src="@Url.Content("~/fonts/grid-delete-icon1.gif")" title="Hủy điểm TN học viên" />
                                                </a>
                                                @*}*@


                                            </div>
                                        </td>
                                    </tr>
                                    i++;
                                }
                            }
                        }

                    </table>
                </div>

                <div class="pagination-sm row" style="clear:both; padding: 5px 0;">
                    @Html.PagedListPager(Model.SearchResults, page => Url.Action("Index", new
   {
       page,
       Model.pDVGTVT_MA,
       Model.pKH_MA,
       Model.pKH_LOP_MA,
       Model.pHV_MA,
       Model.pHV_HOTEN,
       Model.pHV_CMND,
       Model.pHANG_DT,
       Model.pSO_QD_TN
   }))
                </div>
            </fieldset>

        </div>
    </div>
</div>

<div id="wait" style="display: none; position:absolute; top: 10%; right: 10%; padding: 2px; z-index: 99999">
    <img src="~/fonts/images/loading16.gif" width="65" height="65" />
</div>



<!-- delete modal placeholder-->
<div id='deleteModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='deleteModalContent'></div>
        </div>
    </div>
</div>

<!-- modal placeholder-->
<div id='myModal' class='modal fade in'>
    <div class="modal-dialog">
        <div class="modal-content">
            <div id='myModalContent'></div>
        </div>
    </div>
</div>


@section Scripts {
    @Scripts.Render("~/bundles/modalform")
}

<link href="~/Scripts/select2.css" rel="stylesheet" />
<link href="~/Scripts/select2.min.css" rel="stylesheet" />
<script src="~/Scripts/select2.js"></script>
@*//var myVar = $("#start").find('.myClass').val();*@

<script>

    //var row_index = 0;
    //var row;
    //$("#tabledata td").click(function () {
    //    row_index = $(this).parent().index();
    //    row = $(this).parent();
    //    alert(row.index());
    //});

    $(".txtnumber").keypress(function (e) {
        if (e.which == 13) {
            var vReturn = true;
            var thisID = $(this).attr('id');
            var lastNumber = thisID.split('_');
            var _number = lastNumber[lastNumber.length - 1].toString();
            var DTTN_KQTN_LT_ID = 'DTTN_KQTN_LT_' + _number;
            var DTTN_KQTN_TH_ID = 'DTTN_KQTN_TH_' + _number;
            var DTTN_KQTN_TD_ID = 'DTTN_KQTN_TD_' + _number;
            var DTTN_KQTN_CC_ID = 'DTTN_KQTN_CC_' + _number;
            var DTTN_KQTN_TB_ID = 'DTTN_KQTN_TB_' + _number;
            var DTTN_KQTN_TONG_ID = 'DTTN_KQTN_TONG_' + _number;
            var DTTN_KQTN_NGAYTN_ID = 'DTTN_KQTN_NGAYTN_' + _number;

            //mới thêm vào 2017-08-20
            var DTTN_KQTN_TBC_ID = 'DTTN_KQTN_TBC_' + _number;
            var DTTN_KQTN_TKKH_ID = 'DTTN_KQTN_TKKH_' + _number;

            if ($("#" + DTTN_KQTN_NGAYTN_ID).val() == null || $("#" + DTTN_KQTN_NGAYTN_ID).val() == "") {
                $("#" + DTTN_KQTN_NGAYTN_ID).css("border", "solid 1px #b94a48");
                $("#" + DTTN_KQTN_NGAYTN_ID).focus();
                return false;
            }

            //if ($("#" + DTTN_KQTN_LT_ID).val() == null || $("#" + DTTN_KQTN_LT_ID).val() == "") {
            //    $("#" + DTTN_KQTN_LT_ID).css("border", "solid 1px #b94a48");
            //    $("#" + DTTN_KQTN_LT_ID).focus();
            //    return false;
            //}

            //if ($("#" + DTTN_KQTN_TH_ID).val() == null || $("#" + DTTN_KQTN_TH_ID).val() == "") {
            //    $("#" + DTTN_KQTN_TH_ID).css("border", "solid 1px #b94a48");
            //    $("#" + DTTN_KQTN_TH_ID).focus();
            //    return false;
            //}

            //if ($("#" + DTTN_KQTN_TD_ID).val() == null || $("#" + DTTN_KQTN_TD_ID).val() == "") {
            //    $("#" + DTTN_KQTN_TD_ID).css("border", "solid 1px #b94a48");
            //    $("#" + DTTN_KQTN_TD_ID).focus();
            //    return false;
            //}

            //if ($("#" + DTTN_KQTN_CC_ID).val() == null || $("#" + DTTN_KQTN_CC_ID).val() == "") {
            //    $("#" + DTTN_KQTN_CC_ID).css("border", "solid 1px #b94a48");
            //    $("#" + DTTN_KQTN_CC_ID).focus();
            //    return false;
            //}



            var vID = 'ID_' + _number;
            var vHV_DVGTVT_MA = 'HV_DVGTVT_MA_' + _number;
            var vHV_KH_MA = 'HV_KH_MA_' + _number;
            var vDTTN_ID = 'DTTN_ID_' + _number;
            var vHV_MA = 'HV_MA_' + _number;
            var vDTTN_QD_ID = 'DTTN_QD_ID_' + _number;
            var vDTTN_HGPLX_MA = 'DTTN_HGPLX_MA_' + _number;


            var data = {
                ID: $("#" + vID).val(),
                DTTN_KQTN_DVGTVT_MA: $("#" + vHV_DVGTVT_MA).val(),
                DTTN_KQTN_KH_MA: $("#" + vHV_KH_MA).val(),
                DTTN_KQTN_DTTN_ID: $("#" + vDTTN_ID).val(),
                DTTN_KQTN_HV_MA: $("#" + vHV_MA).val(),
                DTTN_KQTN_DTTN_QD_ID: $("#" + vDTTN_QD_ID).val(),
                DTTN_KQTN_LT: $("#" + DTTN_KQTN_LT_ID).val(),
                DTTN_KQTN_TH: $("#" + DTTN_KQTN_TH_ID).val(),
                DTTN_KQTN_TD: $("#" + DTTN_KQTN_TD_ID).val(),
                DTTN_KQTN_CC: $("#" + DTTN_KQTN_CC_ID).val(),
                DTTN_KQTN_TONG: $("#" + DTTN_KQTN_TONG_ID).val(),
                DTTN_KQTN_TB: $("#" + DTTN_KQTN_TB_ID).val(),
                DTTN_KQTN_NGAYTN: $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[1] + "/" + $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[0] + "/" + $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[2],
                DTTN_HGPLX_MA: $("#" + vDTTN_HGPLX_MA).val(),
                DTTN_KQTN_TBC: $("#" + DTTN_KQTN_TBC_ID).val(),
                DTTN_KQTN_TKKH: $("#" + DTTN_KQTN_TKKH_ID).val()
            }

            var position = $(this).position();
            //$("p:last").text("left: " + position.left + ", top: " + position.top);
            //alert("left: " + position.left + ", top: " + position.top);
            $("#wait").attr("style", "display:block;position:absolute;top:" + position.top + ";left:" + position.top + ";padding:2px; z-index:99999");

            $.ajax({
                url: '/GPS_DiemTotNghiep/InsertOrUpdate/',
                type: 'POST',
                traditional: true,
                data: { modeljson: JSON.stringify(data) },
                dataType: 'json',
                success: function (response) {
                    $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");
                    if (response.status) {
                        //set href edit
                        var vedit = 'edit_' + _number;
                        $("#" + vedit).attr("href", "/GPS_DiemTotNghiep/Edit/" + response.id.toString() + "?id6=" + $("#" + vDTTN_HGPLX_MA).val());
                        $("#" + vedit).css("display", "block");
                        @*$("#" + vedit).attr("href",  "@Url.Action("Edit", "GPS_DiemTotNghiep", new { id = response.id, id6 = item.DTTN_HGPLX_MA })");*@

                        // ẩn add
                        var vadd = 'add_' + _number;
                        $("#" + vadd).css("display", "none");
                        //set href delete
                        var vdelete = 'delete_' + _number;
                        $("#" + vdelete).attr("href", "/GPS_DiemTotNghiep/Delete/" + response.id.toString());
                        $("#" + vdelete).css("display", "block");

                        //gan laij ID
                        $("#" + vID).val(response.id);

                        //alert("Cập nhật thành công!");
                        //location.reload();
                        toastr.success('Cập nhật thành công!', 'thông báo');

                        //xuống dòng
                        var number_next = (parseInt(_number) + 1).toString();
                        var DTTN_KQTN_LT_ID_NEXT = 'DTTN_KQTN_LT_' + number_next;

                        var txtfind = $('#tabledata').find("#" + DTTN_KQTN_LT_ID_NEXT);
                        if (txtfind != null && txtfind.length > 0) {
                            $("#" + DTTN_KQTN_LT_ID_NEXT).focus();
                        }
                    }
                    else {
                        alert("Lỗi trong quá trình cập nhật!" + "<br/>" + response.message);
                        location.reload();
                    }
                },
                error: function () {
                    $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");
                    alert("Lỗi kết nối với server!");
                    location.reload();
                    $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");


                }
            });
        }
    });

    $(".txtnumber").blur(function () {
        var _val = $(this).val();
        var thisID = $(this).attr('id');
        var lastNumber = thisID.split('_');
        var DTTN_KQTN_LT_ID = 'DTTN_KQTN_LT_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_TH_ID = 'DTTN_KQTN_TH_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_TD_ID = 'DTTN_KQTN_TD_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_CC_ID = 'DTTN_KQTN_CC_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_TB_ID = 'DTTN_KQTN_TB_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_TONG_ID = 'DTTN_KQTN_TONG_' + lastNumber[lastNumber.length - 1].toString();

        //them vào 2017-08-20
        var DTTN_KQTN_TBC_ID = 'DTTN_KQTN_TBC_' + lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_TKKH_ID = 'DTTN_KQTN_TKKH_' + lastNumber[lastNumber.length - 1].toString();

        var tongdiem = 0;
        var trungbinh = 0.00;
        // $("#" + DoiTuongID)
        var _DTTN_KQTN_LT = $("#" + DTTN_KQTN_LT_ID).val() == null || $("#" + DTTN_KQTN_LT_ID).val() == "" ? "0" : $("#" + DTTN_KQTN_LT_ID).val();//  parseFloat("10.33")
        var _DTTN_KQTN_TH = $("#" + DTTN_KQTN_TH_ID).val() == null || $("#" + DTTN_KQTN_TH_ID).val() == "" ? "0" : $("#" + DTTN_KQTN_TH_ID).val();
        var _DTTN_KQTN_TD = $("#" + DTTN_KQTN_TD_ID).val() == null || $("#" + DTTN_KQTN_TD_ID).val() == "" ? "0" : $("#" + DTTN_KQTN_TD_ID).val();
        var _DTTN_KQTN_CC = $("#" + DTTN_KQTN_CC_ID).val() == null || $("#" + DTTN_KQTN_CC_ID).val() == "" ? "0" : $("#" + DTTN_KQTN_CC_ID).val();

        //them vào 2017-08-20
        var _DTTN_KQTN_TBC = $("#" + DTTN_KQTN_TBC_ID).val() == null || $("#" + DTTN_KQTN_TBC_ID).val() == "" ? "0" : $("#" + DTTN_KQTN_TBC_ID).val();


        //  alert(_DTTN_KQTN_LT);
        tongdiem = parseFloat(_DTTN_KQTN_LT) + parseFloat(_DTTN_KQTN_TH) + parseFloat(_DTTN_KQTN_TD) + parseFloat(_DTTN_KQTN_CC);
        $("#" + DTTN_KQTN_TONG_ID).val(tongdiem.toString());
        //  $("#DTTN_KQTN_TONGDIEM").val(tongdiem.toString());

        trungbinh = tongdiem / 4;
        $("#" + DTTN_KQTN_TB_ID).val(trungbinh.toString());

        //them vào 2017-08-20 - tính điểm TKKH:
        var tongketkh = 0.00;
        tongketkh = (parseFloat(_DTTN_KQTN_TBC) + 2 * trungbinh) / 3;
        $("#" + DTTN_KQTN_TKKH_ID).val(tongketkh.toString());

    });

    $(".savediemhocvien").click(function () {
        var vReturn = true;
        var thisID = $(this).attr('id');
        var lastNumber = thisID.split('_');
        var _number = lastNumber[lastNumber.length - 1].toString();
        var DTTN_KQTN_LT_ID = 'DTTN_KQTN_LT_' + _number;
        var DTTN_KQTN_TH_ID = 'DTTN_KQTN_TH_' + _number;
        var DTTN_KQTN_TD_ID = 'DTTN_KQTN_TD_' + _number;
        var DTTN_KQTN_CC_ID = 'DTTN_KQTN_CC_' + _number;
        var DTTN_KQTN_TB_ID = 'DTTN_KQTN_TB_' + _number;
        var DTTN_KQTN_TONG_ID = 'DTTN_KQTN_TONG_' + _number;
        var DTTN_KQTN_NGAYTN_ID = 'DTTN_KQTN_NGAYTN_' + _number;

        //mới thêm vào 2017-08-20
        var DTTN_KQTN_TBC_ID = 'DTTN_KQTN_TBC_' + _number;
        var DTTN_KQTN_TKKH_ID = 'DTTN_KQTN_TKKH_' + _number;


        if ($("#" + DTTN_KQTN_NGAYTN_ID).val() == null || $("#" + DTTN_KQTN_NGAYTN_ID).val() == "") {
            $("#" + DTTN_KQTN_NGAYTN_ID).css("border", "solid 1px #b94a48");
            $("#" + DTTN_KQTN_NGAYTN_ID).focus();
            return false;
        }

        //if ($("#" + DTTN_KQTN_LT_ID).val() == null || $("#" + DTTN_KQTN_LT_ID).val() == "") {
        //    $("#" + DTTN_KQTN_LT_ID).css("border", "solid 1px #b94a48");
        //    $("#" + DTTN_KQTN_LT_ID).focus();
        //    return false;
        //}

        //if ($("#" + DTTN_KQTN_TH_ID).val() == null || $("#" + DTTN_KQTN_TH_ID).val() == "") {
        //    $("#" + DTTN_KQTN_TH_ID).css("border", "solid 1px #b94a48");
        //    $("#" + DTTN_KQTN_TH_ID).focus();
        //    return false;
        //}

        //if ($("#" + DTTN_KQTN_TD_ID).val() == null || $("#" + DTTN_KQTN_TD_ID).val() == "") {
        //    $("#" + DTTN_KQTN_TD_ID).css("border", "solid 1px #b94a48");
        //    $("#" + DTTN_KQTN_TD_ID).focus();
        //    return false;
        //}

        //if ($("#" + DTTN_KQTN_CC_ID).val() == null || $("#" + DTTN_KQTN_CC_ID).val() == "") {
        //    $("#" + DTTN_KQTN_CC_ID).css("border", "solid 1px #b94a48");
        //    $("#" + DTTN_KQTN_CC_ID).focus();
        //    return false;
        //}



        var vID = 'ID_' + _number;
        var vHV_DVGTVT_MA = 'HV_DVGTVT_MA_' + _number;
        var vHV_KH_MA = 'HV_KH_MA_' + _number;
        var vDTTN_ID = 'DTTN_ID_' + _number;
        var vHV_MA = 'HV_MA_' + _number;
        var vDTTN_QD_ID = 'DTTN_QD_ID_' + _number;
        var vDTTN_HGPLX_MA = 'DTTN_HGPLX_MA_' + _number;


        var data = {
            ID: $("#" + vID).val(),
            DTTN_KQTN_DVGTVT_MA: $("#" + vHV_DVGTVT_MA).val(),
            DTTN_KQTN_KH_MA: $("#" + vHV_KH_MA).val(),
            DTTN_KQTN_DTTN_ID: $("#" + vDTTN_ID).val(),
            DTTN_KQTN_HV_MA: $("#" + vHV_MA).val(),
            DTTN_KQTN_DTTN_QD_ID: $("#" + vDTTN_QD_ID).val(),
            DTTN_KQTN_LT: $("#" + DTTN_KQTN_LT_ID).val(),
            DTTN_KQTN_TH: $("#" + DTTN_KQTN_TH_ID).val(),
            DTTN_KQTN_TD: $("#" + DTTN_KQTN_TD_ID).val(),
            DTTN_KQTN_CC: $("#" + DTTN_KQTN_CC_ID).val(),
            DTTN_KQTN_TONG: $("#" + DTTN_KQTN_TONG_ID).val(),
            DTTN_KQTN_TB: $("#" + DTTN_KQTN_TB_ID).val(),
            DTTN_KQTN_NGAYTN: $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[1] + "/" + $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[0] + "/" + $("#" + DTTN_KQTN_NGAYTN_ID).val().split("/")[2],
            DTTN_HGPLX_MA: $("#" + vDTTN_HGPLX_MA).val(),
            DTTN_KQTN_TBC: $("#" + DTTN_KQTN_TBC_ID).val(),
            DTTN_KQTN_TKKH: $("#" + DTTN_KQTN_TKKH_ID).val()
        }

        var position = $(this).position();
        //$("p:last").text("left: " + position.left + ", top: " + position.top);
        //alert("left: " + position.left + ", top: " + position.top);
        $("#wait").attr("style", "display:block;position:absolute;top:" + position.top + ";left:" + position.top + ";padding:2px; z-index:99999");

        $.ajax({
            url: '/GPS_DiemTotNghiep/InsertOrUpdate/',
            type: 'POST',
            traditional: true,
            data: { modeljson: JSON.stringify(data) },
            dataType: 'json',
            success: function (response) {
                $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");
                if (response.status) {
                    //set href edit
                    var vedit = 'edit_' + _number;
                    $("#" + vedit).attr("href", "/GPS_DiemTotNghiep/Edit/" + response.id.toString() + "?id6=" + $("#" + vDTTN_HGPLX_MA).val());
                    $("#" + vedit).css("display", "block");
                    @*$("#" + vedit).attr("href",  "@Url.Action("Edit", "GPS_DiemTotNghiep", new { id = response.id, id6 = item.DTTN_HGPLX_MA })");*@

                    // ẩn add
                    var vadd = 'add_' + _number;
                    $("#" + vadd).css("display", "none");
                    //set href delete
                    var vdelete = 'delete_' + _number;
                    $("#" + vdelete).attr("href", "/GPS_DiemTotNghiep/Delete/" + response.id.toString());
                    $("#" + vdelete).css("display", "block");

                    //gan laij ID
                    $("#" + vID).val(response.id);

                    //alert("Cập nhật thành công!");
                    //location.reload();
                    toastr.success('Cập nhật thành công!', 'thông báo');

                    //xuống dòng
                    var number_next = (parseInt(_number) + 1).toString();
                    var DTTN_KQTN_LT_ID_NEXT = 'DTTN_KQTN_LT_' + number_next;

                    var txtfind = $('#tabledata').find("#" + DTTN_KQTN_LT_ID_NEXT);
                    if (txtfind != null && txtfind.length > 0) {
                        $("#" + DTTN_KQTN_LT_ID_NEXT).focus();
                    }

                }
                else {
                    alert("Lỗi trong quá trình cập nhật!" + "<br/>" + response.message);
                    location.reload();
                }
            },
            error: function () {
                $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");
                alert("Lỗi kết nối với server!");
                location.reload();
                $("#wait").attr("style", "display:none;position:absolute;top:20%;left:50%;padding:2px; z-index:99999");


            }
        });


    });

</script>

@*var toasts = [
        new Toast('error', 'toast-bottom-full-width', 'This is positioned in the bottom full width. You can also style the icon any way you like.'),
        new Toast('info', 'toast-top-full-width', 'top full width'),
        new Toast('warning', 'toast-top-left', 'This is positioned in the top left. You can also style the icon any way you like.'),
        new Toast('success', 'toast-top-right', 'top right'),
        new Toast('warning', 'toast-bottom-right', 'bottom right'),
        new Toast('error', 'toast-bottom-left', 'bottom left')
    ];*@

<script type="text/javascript">
    toastr.options = {
        "debug": false,
        "positionClass": "toast-bottom-right",
        "fadeIn": 500,
        "fadeOut": 2000,
        "timeOut": 1000,
        "extendedTimeOut": 1000

    }


    $(document).tooltip();


    $("#tabledata").find("input[type=text]").not("input[id^='DTTN_KQTN_NGAYTN']").number(true, 2);
    $("#tabledata").find("input[id^='DTTN_KQTN_NGAYTN']").datepicker({
        changeMonth: true,
        changeYear: true,

        dateFormat: 'dd/mm/yy'
    });

    $("#tabledata").find("input[id^='DTTN_KQTN_NGAYTN']").mask("99/99/9999", { placeholder: "dd/mm/yyyy" });
    //$("#Table1").find('input[type=number]').maskNumber({ integer: true, decimal: '', thousands: '' });


    $.ajaxSetup({ cache: false });

    $("a[data-modal]").on("click", function (e) {
        // alert(this.href);
        $('#myModalContent').load(this.href, function () {
            // alert(this.href);

            $('#myModal').modal({
                /*backdrop: 'static',*/
                keyboard: true
            }, 'show');

            bindForm(this);
        });

        return false;
    });

    function bindForm(dialog) {

        $('form', dialog).submit(function () {
            //  alert(dialog);
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    //  alert(result.success);
                    if (result.success) {

                        $('#myModal').modal('hide');
                        //Refresh
                        location.reload();
                        //$('#replacetarget').load(result.url); //  Load data from the server and place the returned HTML into the matched element
                    } else {
                        $('#myModalContent').html(result);
                        bindForm(dialog);
                    }
                }
            });
            return false;
        });
    }


</script>

<script type="text/javascript">

    $(document).ready(function () {

        var pageSize = 20;
        var optionListUrl = '@Url.Action("Select2KH_MA_TN", "GPS_Ajax")';

        $('#KH_MA_ddl').select2(
                {
                    ajax: {
                        delay: 50,
                        url: optionListUrl,
                        dataType: 'json',

                        data: function (params) {
                            /// params.page = params.page || 1;
                            return {
                                searchTerm: params.term,
                                dvgtvt_ma: $("#DVGTVT_MA_dll").val()
                                //pageNumber: params.page results: JSON.parse(data)
                            };
                        },
                        processResults: function (data, params) {

                            return {
                                results: data.Results
                            };
                        }
                    },
                    placeholder: "-- Chọn khóa học --",
                    minimumInputLength: 2,
                    allowClear: true,
                    language: { inputTooShort: function () { return 'Nhập lớn hơn 2 ký tự để tìm kiếm khóa học'; } }
                });
    }
    );

</script>


